home *** CD-ROM | disk | FTP | other *** search
- Path: ni1.ni.net!usenet
- From: Jeff Nikodym <jeffnik@ni.net>
- Newsgroups: comp.lang.c++
- Subject: [Q] MSVC2.0 Windows Messaging...
- Date: Thu, 08 Feb 1996 20:34:47 -0800
- Organization: Network Intensive
- Message-ID: <311ACEE7.7679@ni.net>
- NNTP-Posting-Host: jeffnik.ni.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- I'm new to MSVC2.0, and I'm trying my hand at Winsock for
- the first time (probably a BAD combination!). I cant get the
- WSAAsyncGetHostByAddr() function to call back my message handler.
- The WSA function runs, and I see the command go over the modem
- (I have an external), and the RCV light blinks as well (I assume
- this is an ACK *OR* possibly the information being returned).
- Problem is, once done, the WSA function should send a message back
- to the window, which should cause the window to start the OnmyMsg()
- message handler routine. The handle returned by the WSA
- function after the call is valid (1 the first call, 2 the second
- call, etc) and the WSAGetLastError function returns no error,
- but the hostent struct (myHostEnt) contains no new information, and
- OnmyMsg() handler never runs. Here is the code that relates to this
- discussion. If some C++ expert could give it a quick scan, and tell
- me what I might be doing wrong, Id greatly appreciate it. Thanks!
-
-
- ***** Heres the MainFrame.h file *****
- class CMainFrame : public CFrameWnd
- {
- protected: // create from serialization only
- CMainFrame();
- DECLARE_DYNCREATE(CMainFrame)
-
- // Attributes
- public:
-
- // Operations
- public:
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CMainFrame)
- //}}AFX_VIRTUAL
-
-
- // Implementation
- public:
- virtual ~CMainFrame();
- #ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
- #endif
-
- protected: // control bar embedded members
- CStatusBar m_wndStatusBar;
- CToolBar m_wndToolBar;
-
- // Generated message map functions
- protected:
- //{{AFX_MSG(CMainFrame)
- afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
- afx_msg void OnHelpInfo();
- afx_msg void OnmyMsg();
- afx_msg void OnAppExit();
- afx_msg void OnHelpHost();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-
- };
-
-
- ***** In the MainFrame.CPP file: *****
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
-
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
-
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(IDD_HELP_INFO, OnHelpInfo)
- ON_COMMAND(WM_myMsg, OnmyMsg)
- ON_COMMAND(ID_APP_EXIT, OnAppExit)
- ON_COMMAND(IDD_HELP_HOST, OnHelpHost)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- void CMainFrame::OnHelpInfo()
- {
- // TODO: Add your command handler code here
- char myBuffer[100];
- int myBufferLen=100,LastError;
- unsigned long addr;
-
- HANDLE PASCAL FAR my_Handle;
-
- addr=inet_addr("199.107.69.182");
- my_Handle=WSAAsyncGetHostByAddr(m_hWnd, WM_myMsg,(const char *) &addr, 4, PF_INET, (char
- FAR *)&myHostEnt,sizeof(myHostEnt));
- LastError=WSAGetLastError();
- wsprintf(myBuffer, "Handle: %d Last Error: %d
- WinsockInitialized=%d",my_Handle,LastError,WinsockInitialized);
- if (LastError!=0)MessageBox(myBuffer);
-
- }
-
- void CMainFrame::OnmyMsg()
- {
- // TODO: Add your command handler code here
- MessageBox("Message Received","Yeah!",MB_OK);
- }
-
- void CMainFrame::OnAppExit()
- {
- if (WinsockInitialized==TRUE)
- {
- WSACleanup();
- }
- }
-
-
-
- ***** After running I get: *****
-
- Loaded symbols for 'C:\WINDOWS\SYSTEM\MFC30D.DLL'.
- MFC30D.DLL Initializing!
- First-Chance Exception in server.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
- Thread 0xFFFA217B terminated, exit code -1 (0xFFFFFFFF).
- MFC30D.DLL Terminating!
- Process 0xFFF904D7 terminated, exit code 0 (0x0).
-